package s16.ch19.ex1;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class MyReflections {

	public static void main(String[] args) throws NoSuchFieldException,
			SecurityException, IllegalArgumentException,
			IllegalAccessException, NoSuchMethodException,
			InvocationTargetException {
		Person person = new Person();

		person.setName("andrew");
		Field[] declaredFields = Person.class.getDeclaredFields();
		for (Field field : declaredFields) {
			System.out.println(field);
		}
		Field field = Person.class.getDeclaredField("name");
		field.setAccessible(true);
		field.set(person, "Kriss");

		Method[] declaredMethods = Person.class.getDeclaredMethods();
		for (Method method : declaredMethods) {
			System.out.println(method);

		}

		Method method = Person.class.getDeclaredMethod("setName", String.class);
		method.invoke(person, "Mark");

		System.out.println(person.getName());

	}
}
